/*
 * @lc app=leetcode.cn id=307 lang=csharp
 *
 * [307] 区域和检索 - 数组可修改
 */

// @lc code=start
public class NumArray {
    private int[] arr = new int[10];
    
    private void Grow(int length)
    {
        int[] newArr = new int[length];
        Array.Copy(arr, newArr, arr.Length);
        arr = newArr;
    }
    public NumArray(int[] nums) {
        if(nums.Length > arr.Length)
        {
            Grow(nums.Length);
        }
        Array.Copy(nums, arr, nums.Length);
    }
    
    public void Update(int index, int val) {
        arr[index] = val;
    }
    
    public int SumRange(int left, int right) 
    {
        int sum = 0;
        for(int i = left; i <= right; i++)
        {
            sum += arr[i];
        }
        return sum;
    }
}

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray obj = new NumArray(nums);
 * obj.Update(index,val);
 * int param_2 = obj.SumRange(left,right);
 */
// @lc code=end

